home *** CD-ROM | disk | FTP | other *** search
- /* DialogBits
- * providing a bunch of dialog manager snippets */
- /*************************************************************
- This sample shows how to deal with many of the most commonly asked Dialog Manager
- questions. Dimming edit lines, using userItems, restricting edit lines to
- specific lengths, and some other stuff is included here.
- The programming style used here is designed to clearly show the specific
- actions I'm taking, _not_ to show good coding practice. Obviously, you will
- want to modify and optimize this code for your specific application.
- C.K. Haun
- Apple Developer Tech Support
- *************************************************************/
- /*
- v 2.0.1 July '92
- Change for version 2.0.1
- Added a variable item, varies between static text and edit text.
- Lots of folks have asked how to do this, and this shows the safest
- way to do so.
- Is this a good interface (switching between static and edit text)?
- I dunno, I've had many people say "NO! Never do that!" and others say
- "Yeah, if it makes sense.". I'm not making any value judgements, it's
- your applications, if it makes sense to you have fun.
- */
-
- /*
-
- v 2.0 April '92
- Changes for version 2.0
- If available, use the new Dialog Manager routines.
- Added a control item
- Added code to check for DialogDispatch trap
- Added code to show how to check for 'Paste' in a size-limited edit field
-
- */
-
- //updates 8/96: Prefix.h added as prefix file for 68K and PPC projects; old
- //routine names changed
-
- // 9/96 fixed gDimEditLineUPP creation -afd
-
- #include <Dialogs.h>
- #include <Controls.h>
- #include <QuickDraw.h>
- #include <Windows.h>
- #include <ToolUtils.h>
- #include <OSUtils.h>
- #include <Menus.h>
- #include <Fonts.h>
- #include <resources.h>
- #include <Sound.h>
- #include <Traps.h>
- #include <Gestaltequ.h>
- #include <Memory.h>
- #include <Scrap.h>
- #include <TextEdit.h>
- #include <Icons.h>
- /* item numbers */
-
- /* this stuff would normally be in your .h file, but in this simple example */
- /* I just put them here */
- /* I like enums, hate #defines */
- enum {
- /* ok and cancel are already defined in Dialogs.h */
- kTitleItem = 3,
- kFredIconItem,
- kBottomEditLine,
- kSpinItem,
- kTopEditLine,
- kEditCheckBox,
- kDimmingBox,
- kSayClickFred,
- kSayWhichVersItem,
- kScrollControlItem,
- kSayRotationSpeedItem,
- kSlowWordItem,
- kFastWordItem,
- /* 2.0.1 */
- kStatTextVaryItem,
- kEditTextVaryItem,
- kVaryTextCheckBoxItem,
- kBorderBox
- };
- enum {
- kSampleDialog = 128,
- kBaseSpinIcon = 129
- };
- enum {
- kSoundID = 128,
- kFredIconID = 128,
- kSysEnvironsVersion = 1,
- kNotWord = 128
- };
- /* key equates */
- enum {
- kEnterKey = 0x03,
- kTabKey = 9,
- kReturnKey = 0x0D,
- kBackSpace = 8,
- kEscKey = 0x1B,
- kLeftArrow = 0x1C,
- kRightArrow,
- kUpArrow,
- kDownArrow,
- kDeleteKey = 0x7F
- };
-
- /* prototypes */
- ControlHandle SnatchHandle(DialogPtr thebox, short theGetItem);
- void SpinIt(DialogPtr theDialog);
- pascal Boolean filterIt(DialogPtr inputDialog, EventRecord *myDialogEvent, short *theDialogItem);
- Boolean IsEditKey(char theKey, short modifiers);
- void IBeamIt(WindowPtr dwind);
- pascal void BorderDefault(WindowPtr dwind, short dinum);
- pascal void DimEditLine(WindowPtr dwind, short dinum);
- pascal void DoScrollArrows(ControlHandle theControl, short thePart);
- Boolean TrapAvailable(short tNumber);
- short HasSelectionRange(DialogPeek inputDialog);
- pascal void NOPRoutine(WindowPtr dwind, short dinum);
-
- /* not strictly necessary, this is set by a call to */
- /* TrapAvailable to see if the new dialog dispatch routines are in. */
- /* So, you could call TrapAvail all the time instead of using this global */
- Boolean gNewDialog = true;
-
- ControlActionUPP gControlActionUPP; /* added to support the Universal Interfaces */
- ModalFilterUPP gModalFilterUPP;
-
- UserItemUPP gNOPRoutineUPP; /* UPPs for our user item routines */
- UserItemUPP gBorderDefaultUPP;
- UserItemUPP gDimEditLineUPP;
-
- void main(void)
- {
- DialogPtr myDialog = nil; /* the dialog wee're using */
- short hitItem = 0; /* hitItem for ModalDialog */
- Rect tempRect; /* these three are here for all the GetDialogItem/SetDialogItem calls*/
- short tempItem;
- Handle tempHandle;
- Boolean tempBool; /* a temporary boolean (now THAT'S a helpful comment */
- Handle theSound;
- Str255 tempString, tempString2;
- /* start up managers */
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- /* set up our control action UPP */
- gControlActionUPP = NewControlActionProc(DoScrollArrows);
-
- /* set up our modal filter UPP */
- gModalFilterUPP = NewModalFilterProc(filterIt);
-
- /* create the UPPs for out user items here */
- gNOPRoutineUPP = NewUserItemProc(NOPRoutine);
- gBorderDefaultUPP = NewUserItemProc(BorderDefault);
- gDimEditLineUPP = NewUserItemProc(DimEditLine);
-
- /* get our dialog. It is created HIDDEN, and shown after I set all */
- /* the user items to their functions */
- myDialog = GetNewDialog(kSampleDialog, nil, (WindowPtr)-1);
-
- /* See if the DialogDispatch trap is available for using the new calls */
- gNewDialog = TrapAvailable(_DialogDispatch);
-
- gNewDialog = true;
-
- /* add a NOT word to my string if they aren't */
- if (gNewDialog == false) {
- Handle theWord = GetResource('STR ', kNotWord);
- if (theWord) {
- HLock(theWord);
- GetDialogItemText(theWord, tempString2);
- ParamText((ConstStr255Param)tempString2, (ConstStr255Param)"", (ConstStr255Param)"", (ConstStr255Param)"");
- HUnlock(theWord);
- ReleaseResource(theWord);
- }
- }
- /* set up our user items for various things */
-
- /* Switch here for Sys 7 or prior */
- /* We'll set up our default and cancel items for gNewDialog, and also shorten */
- /* the DITL to remove the user item I had in there to border the OK button */
- /* Testing for System 7 is appropriate for the new DM calls, but for the */
- /* Append/Delete DITL calls there is a specific selector, so we'll use that also */
- if (gNewDialog) {
- long gestaltReturn;
- OSErr myErr;
- SetDialogDefaultItem(myDialog, ok);
- SetDialogCancelItem(myDialog, cancel);
- SetDialogTracksCursor(myDialog, true);
-
- /* If we have the new calls, we can (and should) take the bounding */
- /* box user item off our item list */
- /* see if ShortenDILT exisits */
- myErr = Gestalt(gestaltDITLExtAttr, &gestaltReturn);
- if ((myErr == noErr) && (gestaltReturn & 0x1)) {
- ShortenDITL(myDialog, 1);
- } else {
-
- /* something weird happened, we have the new Dialog calls but not */
- /* shortenDITL. So make the bounding box item a NOP, but we still */
- /* MUST have it point to something */
- GetDialogItem(myDialog, kBorderBox, &tempItem, &tempHandle, &tempRect);
- SetDialogItem(myDialog, kBorderBox, tempItem, (Handle)gNOPRoutineUPP, &tempRect);
-
- }
- } else {
- /* no new calls, set up the bordering box ourselves */
- GetDialogItem(myDialog, kBorderBox, &tempItem, &tempHandle, &tempRect);
- SetDialogItem(myDialog, kBorderBox, tempItem, (Handle) gBorderDefaultUPP, &tempRect);
- }
-
- /* set up the user item that will dim the edit line when it is disabled */
- GetDialogItem(myDialog, kDimmingBox, &tempItem, &tempHandle, &tempRect);
- SetDialogItem(myDialog, kDimmingBox, tempItem, (Handle)gDimEditLineUPP, &tempRect);
-
- /* make sure the enabled checkbox for the edit line is FALSE */
- tempHandle = (Handle)SnatchHandle(myDialog, kEditCheckBox);
- SetControlValue((ControlHandle)tempHandle, false);
-
- /* and since I want this edit line dimmed when the box first shows up, I'll */
- /* select the other edit line */
- SelectDialogItemText((DialogPtr)myDialog, kTopEditLine, 0, 0);
- /* 2.0.1 adding switchable text*/
- HideDialogItem(myDialog,kEditTextVaryItem);
-
-
- /* show it */
- ShowWindow((WindowPtr)myDialog);
-
- /* draw it once */
- DrawDialog(myDialog);
-
- do {
- ModalDialog(gModalFilterUPP, &hitItem);
- switch (hitItem) {
- case kFredIconItem:
- /* if they click on Fred, have him express his opinion */
- theSound = GetResource('snd ', kSoundID);
- if (theSound != nil) {
- SndPlay(nil, (SndListHandle)theSound, false);
- ReleaseResource(theSound);
- }
- break;
- case kEditCheckBox:
- /* edit line dim checkbox */
-
- tempHandle = (Handle)SnatchHandle(myDialog, kEditCheckBox);
- tempBool = GetControlValue((ControlHandle)tempHandle);
- if (tempBool == true) tempBool = false;
- else tempBool = true;
- SetControlValue((ControlHandle)tempHandle, tempBool);
- if (tempBool == false) {
- /* they turned the edit line off, we need to switch out of the EL if its */
- /* active */
- if (((DialogPeek)myDialog)->editField + 1 == kBottomEditLine)
- SelectDialogItemText((DialogPtr)myDialog, kTopEditLine, 0, 0);
- }
- /* whatever they did, invalidate the rect so the edit line is dimmed/not */
- /* dimmed correctly */
- GetDialogItem(myDialog, kDimmingBox, &tempItem, &tempHandle, &tempRect);
- /* way paranoid, but once you've invalidated a rect in the wrong port */
- /* you never want to do it again */
- SetPort(myDialog);
- InvalRect(&tempRect);
- break;
- case kVaryTextCheckBoxItem:
- tempHandle = (Handle)SnatchHandle(myDialog, kVaryTextCheckBoxItem);
- tempBool = GetControlValue((ControlHandle)tempHandle);
- tempBool = tempBool ? false : true;
- SetControlValue((ControlHandle)tempHandle,tempBool);
- if(tempBool){
- HideDialogItem(myDialog,kStatTextVaryItem);
- ShowDialogItem(myDialog,kEditTextVaryItem);
- } else {
- /* when we switch from edit text to static text, we want the */
- /* static text to say the same thing as the edit text, so let's do that */
- GetDialogItemText((Handle)SnatchHandle(myDialog, kEditTextVaryItem), tempString);
- SetDialogItemText((Handle)SnatchHandle(myDialog, kStatTextVaryItem),tempString);
- HideDialogItem(myDialog,kEditTextVaryItem);
- ShowDialogItem(myDialog,kStatTextVaryItem);
-
- }
- /* whatever we did with this, we have to change the selection */
- if(tempBool){
- /* if they just turned us on, move the selection to us */
- SelectDialogItemText((DialogPtr)myDialog, kEditTextVaryItem, 0, 0);
-
- } else {
- /* else move to the top line */
- SelectDialogItemText((DialogPtr)myDialog, kTopEditLine, 0, 0);
-
- }
- break;
-
- }
- }
- while (hitItem != ok && hitItem != cancel);
- DisposeDialog(myDialog);
- InitCursor(); /* Init to prevent I-beam from hanging around in some circumstances */
- } /* end main */
-
- /* My dialog filter. It's pretty crowded here, since I'm showing lots of */
- /* stuff. You'd of course want it neatened up a bit */
- pascal Boolean filterIt(DialogPtr inputDialog, EventRecord *myDialogEvent, short *theDialogItem)
- {
- WindowPtr tempWindowPtr;
- ModalFilterUPP theModalProc;
- char theKey;
- Rect tempRect;
- short tempItem;
- Handle tempHandle;
- long tilticks;
- Boolean returnVal = false;
- char tempKey;
- Str255 myStr;
- long offset;
- short selection;
- long scrapLen;
- short resultLen;
- Point mousePoint;
- Boolean hiLit = false;
- Point tempPoint;
- short thePart;
- ControlHandle returnedControl;
- OSErr myErr;
- Boolean wasAKey = false;
- /* save the current port, and set the port to us */
- GetPort(&tempWindowPtr);
- SetPort(inputDialog);
-
- /**********************************************************************/
- /* Use something like this if you want to do any idle time drawing in your */
- /* dialog, like a clock, flashing cursor, or a classy animated icon like I'm using */
- /**********************************************************************/
- SpinIt(inputDialog);
-
- /**********************************************************************
- IBeamIt changes the cursor to an IBeam cursor when the cursor is over
- the active edit line.
- Of course, if we're in System 7, we have already made the DialogTracksCursor
- call, so we don't need this.
- **********************************************************************/
- if (gNewDialog == false)
- IBeamIt(inputDialog);
-
- /*************************************************************/
- /* Some key filtering schemes follow. The first is the standard filter to */
- /* recognize 'return' as OK and 'ESC' as cancel. What this really means */
- /* is that I never ever want to have to use the mouse to click the cancel */
- /* buttton ever again, you can just cut and paste this code from now on. */
- /***********************************************************************/
- /* do standard filtering for escape and return as OK and Cancel aliases */
- /* We also invert the button in the dialog, so the user get's visual feedback */
- /* about the action they just took */
- /* Again, if we're using the new calls, then we don't need to do this particular */
- /* filtering */
- wasAKey = (myDialogEvent->what == keyDown) || (myDialogEvent->what == autoKey);
- /* this 'if' has a double key check because of the 'tab' key restriction */
- /* I'm doing. If the new dialog manager calls are being used, we do NOT */
- /* want to pass the tab key through to the standard filter, since it will */
- /* tab to the other edit line even if we have it turned off */
- if ((gNewDialog == false || (wasAKey && ((myDialogEvent->message & charCodeMask) == kTabKey)) ) && wasAKey) {
- theKey = myDialogEvent->message & charCodeMask;
- switch (theKey) {
- case kReturnKey:
- case kEnterKey: /* enter key */
- /* This filters for Return or Enter as item 1, and Esc as item 2 */
- *theDialogItem = ok; /* change whatever the current item is to the OK item */
- /* now we need to invert the button */
- HiliteControl(SnatchHandle(inputDialog, ok), 10);
- Delay(8, &tilticks); /* wait about 8 ticks so they can see it */
- HiliteControl(SnatchHandle(inputDialog, ok), false);
- SetPort(tempWindowPtr);
- returnVal = true;
- break;
- /* This filters the escape key as the same as item 2 (the canx button, usually ) */
- case kEscKey:
- *theDialogItem = cancel;
- HiliteControl(SnatchHandle(inputDialog, cancel), 10);
- Delay(8, &tilticks); /* wait about 8 ticks so they can see it */
- HiliteControl(SnatchHandle(inputDialog, cancel), false);
- returnVal = true;
- break;
- case kTabKey:
- /* I'm filtering the tab key here so the user cannot tab to */
- /* my inactive edit line */
- if (GetControlValue((ControlHandle)SnatchHandle(inputDialog, kEditCheckBox)) == false){
-
- returnVal = true; /* don't allow edit line swaps */}
- break;
- }
- }
-
- /********************************************************************************/
- /* Here's another kind of key filtering you need every so often, text or numeric */
- /* filtering. In this case, we're only going to allow non-numeric characters in */
- /* the second edit line we have installed in this dialog */
- /* Any number will be eaten, and a beep generated */
- /**************************************************/
- if (wasAKey) {
- theKey = myDialogEvent->message & charCodeMask;
-
- if ((theKey > 0x30 && theKey < 0x39) && ((DialogPeek)inputDialog)->editField + 1 == kBottomEditLine) {
- /* Dang, it's a number and in the wrong edit line, reject it */
- SysBeep(1); /* complain a little */
- returnVal = true; /* tell the dialog manager */
- /* that we handled this already and */
- /* it doesn't have to, so the keystroke will _not_ get */
- /* added to the edit line */
-
- }
- }
-
- /********************************************************************************/
- /* Here's yet another kind of key filtering you need every so often. */
- /* I'm going to restrict the amount of text in the top edit line to just 25 characters */
- /**************************************************/
- /* •• NOTE: Remember Cut/Copy/Paste! */
- /* Before you allow these, you need to see what the result of a Paste (in this case) */
- /* will be, since a Paste can also drive you over the 25 char limit. */
- /* I've modified the function IsEditKey to look for these */
- /* I've also added code that checks to see if there is a selection range, */
- /* since typeing one charater to replace 5 is OK */
-
- /* First, see if it was a key and the top edit line is active */
- if ((wasAKey) && ((DialogPeek)inputDialog)->editField + 1 == kTopEditLine) {
- selection = HasSelectionRange((DialogPeek)inputDialog);
- scrapLen = GetScrap(nil, 'TEXT', &offset);
- GetDialogItem(inputDialog, kTopEditLine, &tempItem, &tempHandle, &tempRect);
- GetDialogItemText(tempHandle, myStr);
- /* calculate the result of adding the scrap to the current record. We use */
- /* this in a few places here */
- resultLen = myStr[0] + (scrapLen - selection);
- theKey = myDialogEvent->message & charCodeMask;
- tempKey = theKey;
- if (tempKey >= 0x61 && tempKey <= 0x7a)
- tempKey -= 0x20;
- if (myStr[0] > 25) { /* over 25, see what it is */
- if (IsEditKey(theKey, myDialogEvent->modifiers)) {
- /* it was an editing key, but it MAY be a command-V. */
- /* If it's a command-V then we won't allow it UNLESS */
- /* there is a slection range AND the new data won't overrun things */
- if ((tempKey == 'V') && (myDialogEvent->modifiers & cmdKey)) {
-
- /* this was a paste. check selection range and scrap len */
- if (resultLen < 26) {
- returnVal = false; /* net result is 25 or less */
- } else {
- SysBeep(1);
- returnVal = true;
- }
- } else {
- returnVal = false; /* don't filter out editing keys */
- }
- } else {
- /* One more check (this can get complicated, huh?) */
- /* We now look to see if there is a selection range. If there */
- /* is a range of 1 or more characters, then the one character they are entering */
- /* now will replace that, and we'll end up with _less_ than 25 (or equal) */
- /* to do this, we have to get the TERecord out of the dialog. */
- /* I'm going to do this in a seperate function */
- if (selection == nil) {
- SysBeep(1); /* complain a little */
- returnVal = true; /* tell the dialog manager that we handled this already and */
- /* it doesn't have to, so the keystroke will _not_ get */
- /* added to the edit line */
- }
- }
- } else {
- /* even if we're less than 25 currently, a Command-V (paste) could put us over */
- /* so check it out */
-
- if ((tempKey == 'V') && (myDialogEvent->modifiers & cmdKey)) {
-
- /* Gettting the scrap with a nil handle, which does not give us data, just */
- /* returns the size */
- if (resultLen > 25) {
- SysBeep(1); /* complain a little */
- returnVal = true; /* tell the dialog manager that we handled this already and */
-
- }
- }
- }
- }
- /* We are doing three checks here in the dialog filter for mouseDown */
- /* events. */
- /* The first checks to see if we're in the icon of that Charismatic Dude */
- /* Fred, and tracks it like a control if we are. */
- /* If we're not, then we may be in our scroll bar, and we have to */
- /* do various things if that is true. */
- /* Or, we may be in the disabled edit line, and we have to disallow clicks on it */
- /* when it's disabled */
-
- if (myDialogEvent->what == mouseDown) {
- mousePoint = (myDialogEvent->where);
- GlobalToLocal(&mousePoint);
- /* First see if we're in Fred */
- GetDialogItem(inputDialog, kFredIconItem, &tempItem, &tempHandle, &tempRect);
- if (PtInRect(mousePoint, &tempRect)) {
- /* invert my icon, and track it whilst the user holds the mouse down */
- InvertRect(&tempRect);
- hiLit = true;
- while (StillDown()) {
- GetMouse(&tempPoint); /* returns point in local coords */
- if (PtInRect(tempPoint, &tempRect)) {
- /* in the rect. See if it's hilighted or not */
- if (hiLit == false) {
- hiLit = true;
- InvertRect(&tempRect);
- }
- } else {
- /* not in the rectangle. If it's hilit, get rid of that */
- if (hiLit == true) {
- hiLit = false;
- InvertRect(&tempRect);
- }
- }
- }
- if (hiLit == true) {
- /* if it's still hilited when the mouse comes up, then that means the */
- /* user stayed in and wants to take this icon action */
- InvertRect(&tempRect); /* clear the hiliting if it's still lit */
- *theDialogItem = kFredIconItem;
- returnVal = true; /* telling the Dialog Manager we handled it, pass item back */
- }
- } else {
- /* Now see if we're in the scroll bar */
-
- GetDialogItem(inputDialog, kScrollControlItem, &tempItem, &tempHandle, &tempRect);
- if (PtInRect(mousePoint, &tempRect)) {
- /* We're in the scroll bar. */
- /* Now, what does that mean???? */
- /* Well, the Dialog Manager will automatically call FindControl and TrackControl */
- /* and set the control value (in the case of scroll thumbs) */
- /* on controls added to your dialog, and in many cases that's all you're going */
- /* to need. */
- /* But, ModalDialog does NOT pass back a part code, so if the userPerson */
- /* clicked on the thumb or arrows of the scroll bar, you won't know, you'll */
- /* just know that the scroll bar was clicked in.*/
- /* That's not enough, so we'll to an initial check to see where the control */
- /* was hit */
- thePart = FindControl(mousePoint, inputDialog, &returnedControl);
- /* if the hit was in an arrow or page area, we'll handle it ourselfs */
- if (thePart != 129) {
- TrackControl(returnedControl, mousePoint, gControlActionUPP);
- returnVal = true;
- }
- /* if it was in the thumb, we'll just fall through and let the Dialog Manager */
- /* handle it for us */
- } else {
- /* first see if we even care about this click. If the check box is true, then */
- /* both edit lines are active, let the dialog manager handle it */
- if (GetControlValue(SnatchHandle(inputDialog, kEditCheckBox))) {
- returnVal = false; /* DM will handle */
- } else {
- /* OK, so the edit line checkbox is NOT set, which means that we don't want */
- /* hits in the inactive edit line to do anything. So, see if the hit was */
- /* in the edit line, and report 'true' if it was, telling the Dialog Manager that */
- /* you handled the event and it should do nothing */
- GetDialogItem(inputDialog, kBottomEditLine, &tempItem, &tempHandle, &tempRect);
- if (PtInRect(mousePoint, &tempRect)) {
- returnVal = true;
- } else {
- returnVal = false;
- }
- }
- }
- }
- }
- /* one final thing if we're under System 7, */
- /* calling the standard filter. */
- /* You MUST call the standard filter if you want any of the */
- /* new things to happen! */
- /* The OK button border, cursor tracking, and the rest ONLY */
- /* happen if you call the filter! */
- /* I am also only doing this if the returnValue is still false. If I have */
- /* set it to true somewhere in here, I don't want to call the stdFilter */
- if (gNewDialog && !returnVal) {
-
- myErr = GetStdFilterProc(&theModalProc);
- if (myErr == noErr)
- returnVal = CallModalFilterProc(theModalProc, inputDialog, myDialogEvent, theDialogItem);
- }
- return(returnVal);
- } /* end filterIt */
-
- /* SpinIt animates my fancy icon */
- void SpinIt(DialogPtr theDialog)
- {
- static short pos;
- static long count;
- Handle myIcon;
- Rect tempRect;
- short tempItem;
- Handle tempHandle;
- /* I'm adjusting the speed of the spin based on the value of the scroll bar */
- if (TickCount() > count + (10 - GetControlValue(SnatchHandle(theDialog, kScrollControlItem)))) {
- count = TickCount(); /* reset count to next value */
- myIcon = GetIcon(pos + kBaseSpinIcon);
- /* you could have a rect in this function, but that'd require you to change it all
- * the time when you move the item around in your dialog. So, we'll reference it
- * from the dialog record instead */
- /* make sure we really got the handle */
- if (myIcon != nil) {
- GetDialogItem(theDialog, kSpinItem, &tempItem, &tempHandle, &tempRect);
- PlotIcon(&tempRect, myIcon);
- ReleaseResource(myIcon);
- }
- pos++;
- if (pos > 3)
- pos = 0;
- }
- } /* end SpinIt */
-
- /* BorderDefault draws a heavy border around the default button (in this case the OK button ) */
- /* Again, not necessary if the new DM calls are in */
- pascal void BorderDefault(WindowPtr dwind, short dinum)
- {
- #pragma unused (dinum)
- short itemtype;
- Handle itemhandle;
- Rect borderRect;
- GetDialogItem(dwind, ok, &itemtype, &itemhandle, &borderRect);
- /* ok is defined as 1 in the interfaces. If you'd like another item outlined, */
- /* change this number, of course. */
- InsetRect(&borderRect, -4, -4);
- PenSize(3, 3);
- FrameRoundRect(&borderRect, 16, 16);
- PenSize(1, 1);
- } /* end BorderDefault */
-
- /* This userItem dims the bottom edit line if the check box is not checked */
- pascal void DimEditLine(WindowPtr dwind, short dinum)
- {
- ControlHandle tempCont;
- tempCont = SnatchHandle(dwind, kEditCheckBox);
- /* only do it if the checkbox is false */
- if (GetControlValue(tempCont) == false) {
- PenState thePen;
- short itemType;
- Handle itemHandle;
- Rect dimRect;
- /* Save and restore the pen state so we don't mess things up for other */
- /* drawing routines */
- GetPenState(&thePen);
- GetDialogItem(dwind, dinum, &itemType, &itemHandle, &dimRect);
- PenMode(notPatBic);
- PenPat(&qd.gray);
- PaintRect(&dimRect);
- SetPenState(&thePen);
-
- }
- } /* end DimEditLine */
-
- /* a little utility to see if the current key is an edit-type key */
- Boolean IsEditKey(char theKey, short modifiers)
- {
- register qq;
- Boolean returnVal = false;
- char editChars[] = {
- kLeftArrow, kUpArrow, kRightArrow, kDownArrow, kBackSpace, kEscKey
- };
- char commandEdits[] = {
- 'C', 'V', 'P'
- };
- for (qq = 0; qq < sizeof(editChars) / sizeof(char); qq++) {
- if (theKey == editChars[qq])
- returnVal = true;
- }
- if (returnVal != true && (modifiers & cmdKey)) {
- /* check for XCP */
- /* Do you want me to use toupper? What! And link in all of StdLib! aggggg */
- if (theKey >= 0x61 && theKey <= 0x7a)
- theKey -= 0x20;
- for (qq = 0; qq < sizeof(commandEdits) / sizeof(char); qq++) {
- if (theKey == commandEdits[qq])
- returnVal = true;
- }
- }
- return(returnVal);
- } /* end IsEditKey */
-
- /* changes the cursor to an IBeam if it's over an active edit line, or to the */
- /* arrow if it's not */
- /* Again, not necessary if the new DM calls are in */
- void IBeamIt(WindowPtr dwind)
- {
- Point mouseAt;
- short itemtype;
- Handle itemhandle;
- Rect borderRect;
- short itemNum;
- /* first get the current edit line out of the dialog record */
- itemNum = ((DialogPeek)dwind)->editField + 1; /* always stored 1 less */
- GetDialogItem(dwind, itemNum, &itemtype, &itemhandle, &borderRect);
- GetMouse(&mouseAt);
- if (PtInRect(mouseAt, &borderRect)) {
- SetCursor(*(GetCursor(1)));
- } else {
- /* This means I'm callng InitCursor every time through my filter */
- /* this is a little excessive (ha!) but doesn't hurt anything. */
- /* You could set a global or something if this really offends you */
- InitCursor();
-
- }
- } /* end IBeamIt */
-
- /* Gets the ControlHandle for the item you want in the dialog box thebox. */
- /* Handy for setting checkboxes and radio buttons */
- /* This is the _most_ copied routine from this file */
- ControlHandle SnatchHandle(DialogPtr thebox, short theGetItem)
- {
- short itemtype;
- Rect itemrect;
- Handle thandle;
-
- GetDialogItem(thebox, theGetItem, &itemtype, &thandle, &itemrect);
- return((ControlHandle)thandle);
- } /* end SnatchHandle */
-
- /* This little routine adjusts the scroll bar during TrackControl */
- pascal void DoScrollArrows(ControlHandle theControl, short thePart)
- {
- short currentVal = GetControlValue(theControl);
- short offSet = 0;
- switch (thePart) {
- case 20:
- offSet = -1;
- break;
- case 21:
- offSet = 1;
- break;
- case 22:
- offSet = -3;
- break;
- case 23:
- offSet = 3;
- break;
-
- }
- /* set the control value to the new one, as long as it doesn't pass limits */
- currentVal += offSet;
- if (currentVal < 1)
- currentVal = 1;
- if (currentVal > 10)
- currentVal = 10;
- SetControlValue(theControl, currentVal);
-
- } /* end DoScrollArrows */
-
- short HasSelectionRange(DialogPeek inputDialog)
- {
- TEHandle theTERecord = inputDialog->textH;
- short returnVal = (*theTERecord)->selEnd -(*theTERecord)->selStart;
-
- return(returnVal);
- } /* end HasSelectionRange */
-
- /* This NOP routine is here in case the ShortenDITL call is not */
- /* available but the new dialog manager calls are. In that case I don't */
- /* want to have the bordering box, but I have to have the user item */
- /* pointing at something */
- pascal void NOPRoutine(WindowPtr dwind, short dinum)
- {
- #pragma unused (dwind,dinum)
- } /* end NOPRoutine */
-
- // check to see if a given trap is implemented. We follow IM VI-3-8.
-
- Boolean TrapAvailable(short theTrap)
- {
- TrapType theTrapType;
- short numToolboxTraps;
-
- if ((theTrap & 0x0800) > 0)
- theTrapType = ToolTrap;
- else
- theTrapType = OSTrap;
-
- if (theTrapType == ToolTrap)
- {
- theTrap = theTrap & 0x07ff;
- if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xaa6e, ToolTrap))
- numToolboxTraps = 0x0200;
- else
- numToolboxTraps = 0x0400;
- if (theTrap >= numToolboxTraps)
- theTrap = _Unimplemented;
- };
-
- return (NGetTrapAddress(theTrap, theTrapType) != NGetTrapAddress(_Unimplemented, ToolTrap));
- }
-